{$CLEO .s}
{$INCLUDE_ONCE ../cleo_tester.inc}

script_name '0AD4'
test("0AD4 (scan_string)", tests)
terminate_this_custom_script


function tests
    it("should scan numbers", test1)
    it("should scan characters", test2)
    it("should scan strings", test3)
    it("should report arg count missmatch", test4)
    it("should respect target string size", test5)
    return

    function test1
        scan_string {string} "input 1 2 4 8.0 16.0 32.0" {format} "input %d %d %d %f %f %f" {var_nValues} 0@ {var_values} 1@ 2@ 3@ 4@ 5@ 6@
        assert_result_true()
        assert_eq(0@, 6) // read values count
        assert_eq(1@, 1)
        assert_eq(2@, 2)
        assert_eq(3@, 4)
        assert_eqf(4@, 8.0)
        assert_eqf(5@, 16.0)
        assert_eqf(6@, 32.0)
    end
    
    function test2
        scan_string {string} "ABC" {format} "%c%c%c" {var_nValues} 0@ {var_values} 1@ 2@ 3@
        assert_result_true()
        assert_eq(0@, 3) // read values count
        assert_eq(1@, 0x41) // A
        assert_eq(2@, 0x42) // B
        assert_eq(3@, 0x43) // C
    end
    
    function test3
        scan_string {string} "some testing text" {format} "%s %s %s" {var_nValues} 0@ {var_values} 1@s 3@s 5@s
        assert_result_true()
        assert_eq(0@, 3) // read values count
        assert_eqs(1@s, "some")
        assert_eqs(3@s, "testing")
        assert_eqs(5@s, "text")
    end
    
    function test4
        3@ = 0xCCCCCCCC
        scan_string {string} "input 1 2" {format} "input %d %d %d" {var_nValues} 0@ {var_values} 1@ 2@ 3@
        assert_result_false()
        assert_eq(0@, 2) // read values count
        assert_eq(1@, 1)
        assert_eq(2@, 2)
        assert_eq(3@, 0xCCCCCCCC) // unchanged
    end
    
    function test5
        1@ = 0x77777777
        2@ = 0x88888888
        3@ = 0x99999999
        4@ = 0xAAAAAAAA
        5@ = 0xBBBBBBBB
        6@ = 0xCCCCCCCC
        7@ = 0xDDDDDDDD
        8@ = 0xEEEEEEEE

        scan_string {string} "first_very_long_test_text second_very_long_test_text" {format} "%s %s" {var_nValues} 0@ {var_values} 1@s 4@v,
        assert_result_true()
        assert_eq(0@, 2) // read values count
        assert_eqs(1@s, "first_ve") // clamped to variable size
        assert_eq(3@, 0x99999999) // unchanged
        assert_eqs(4@v, "second_very_long") // clamped to variable size
        assert_eq(8@, 0xEEEEEEEE) // unchanged
    end
end
